/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.support.g;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Looper;
import android.text.TextUtils;

public class b {
    private static Location a;

    public static void a(boolean paramBoolean, Activity paramActivity) {
        if (Build.VERSION.SDK_INT >= 9)
            paramActivity.setRequestedOrientation((paramBoolean) ? 6 : 7);
        else
            paramActivity.setRequestedOrientation((paramBoolean) ? 0 : 1);
    }

    public static void a(Context paramContext, Location paramLocation)
  {
    if ((paramContext == null) || (paramLocation == null))
      return;
    if ((a != null) && (!(TextUtils.isEmpty(a.getProvider()))))
    {
      l1 = a.getTime();
      if (l1 > 0L)
      {
        long l2 = System.currentTimeMillis() - l1;
        a.a("SupportUtils", new Object[] { "sLastLocation pastTime=", Long.valueOf(System.currentTimeMillis() - l1) });
        if ((l2 > 0L) && (l2 < 1800000L))
        {
          paramLocation.set(a);
          return;
        }
      }
    }
    paramLocation.reset();
    long l1 = System.currentTimeMillis();
    a.a("SupportUtils", new Object[] { "requestLocationUpdates start=" + l1 });
    try
    {
      LocationManager localLocationManager = (LocationManager)paramContext.getApplicationContext().getSystemService("location");
      boolean bool = localLocationManager.isProviderEnabled("network");
      a.a("SupportUtils", new Object[] { "isProviderEnabled=" + bool });
      if ((localLocationManager != null) && (bool))
      {
        1 local1 = new LocationListener(l1, paramLocation, localLocationManager)
        {
          public void onStatusChanged(String paramString, int paramInt, Bundle paramBundle)
          {
          }

          public void onProviderEnabled(String paramString)
          {
          }

          public void onProviderDisabled(String paramString)
          {
          }

          public void onLocationChanged(Location paramLocation)
          {
            a.a("SupportUtils", new Object[] { "onLocationChanged cost=", Long.valueOf(System.currentTimeMillis() - this.a) });
            if ((paramLocation != null) && (!(TextUtils.isEmpty(paramLocation.getProvider()))))
            {
              a.a("SupportUtils", new Object[] { "onLocationChanged=", paramLocation.toString() });
              a.a("SupportUtils", new Object[] { "onLocationChanged pastTime=", Long.valueOf(System.currentTimeMillis() - paramLocation.getTime()) });
              b.a(paramLocation);
              this.b.set(b.a());
            }
            this.c.removeUpdates(this);
          }
        };
        localLocationManager.requestLocationUpdates("network", 0L, 0.0F, local1, Looper.getMainLooper());
        for (int i = 0; (TextUtils.isEmpty(paramLocation.getProvider())) && (i < 7); ++i)
          try
          {
            Thread.sleep(500L);
          }
          catch (InterruptedException localInterruptedException)
          {
            a.c("SupportUtils", new Object[] { localInterruptedException.toString() });
          }
        a.a("SupportUtils", new Object[] { "count=", Integer.valueOf(i) });
        localLocationManager.removeUpdates(local1);
        a.a("SupportUtils", new Object[] { "updateLocation cost=", Long.valueOf(System.currentTimeMillis() - l1) });
      }
    }
    catch (Exception localException)
    {
      a.c("SupportUtils", new Object[] { localException.toString() });
    }
    catch (Error localError)
    {
      a.c("SupportUtils", new Object[] { localError.toString() });
    }
  }
}